package com.briup.estore.web.servlet;

import com.briup.estore.common.result.Result;
import com.briup.estore.common.dto.AddressAddDTO;
import com.briup.estore.common.utils.JsonUtils;
import com.briup.estore.service.AddressService;
import com.briup.estore.service.impl.AddressServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author briup-adam
 * @Date 2023/8/4 上午10:18
 * @Description 用户新增收货地址
 **/
@WebServlet("/address/add")
public class AddressAddServlet  extends  BaseServlet {
    private AddressService addressService=new AddressServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userId = (String) req.getAttribute("userId");
        String data = readData(req);
        AddressAddDTO dto = JsonUtils.toObject(data, AddressAddDTO.class);
        addressService.save(dto,Integer.parseInt(userId));
        writeData(resp, Result.success());
    }
}